package com.prashantdctm.utils;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;



public class EmailUtil {
	public static void main(String[] args) throws AddressException, MessagingException  {
		

	}
	
	public static void sendEmail(String from, String to, String subject, String msgBody)  {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);

		try {
			MimeMessage msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress("prashant.dctm@gmail.com", "Prashant Kumar, GAE "));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
					"prashant.dctm@gmail.com", "Mr. Prashant Kumar"));
			if(subject!=null && subject.length()>0) {
				msg.setSubject(subject);
			} else {
				msg.setSubject("GAE daily servlet response");
			}
			msg.setText(msgBody);
			Transport.send(msg);

		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
	public static void sendEmail(String msgBody, String subject)  {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);

		try {
			MimeMessage msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress("prashant.dctm@gmail.com", "Prashant Kumar, GAE "));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
					"prashant.dctm@gmail.com", "Mr. Prashant Kumar"));
			
			msg.setSubject(subject);
			msg.setText(msgBody);
			Transport.send(msg);

		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

}
